﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="fhdb" content="true">
    <title>收货地址</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
    <link rel="stylesheet" href="css/receivingAddress.css">
    <script type="text/javascript" src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script src="js/jquery.form.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="js/bootstrapValidator.js"></script>
    <script type="text/javascript">
        $(function () {
            $.ajax({
                type: "post",
                url: "../../BaseRefWeb.aspx?stype=ISpAddressFun&method=GetWebModel&type=sp",
                success: function (result) {
                    if (result == "") {
                        return;
                    }
                    var data = JSON.parse(result);
                    if (data.msg == "_timeout") {
                        window.location.href = "../UserLogin/Login.html";
                    }
                    $("input[name='name']").val(data.TB_USERNAME)
                    $("input[name='phone']").val(data.TB_PHONE)
                    $("input[name='region']").val(data.TB_DIQU);
                    $("input[name='detailedAddress").val(data.TB_ADDRESS);
                    $("input[name='postalCode").val(data.TB_YZBM);
                    $("#btnBox").text("修改");
                }
            });
            //提交表单数据
            $('#btnBox').click(function (event) {
                /* Act on the event */
                /*手动验证表单，当是普通按钮时。*/
                $('#defaultForm').data('bootstrapValidator').validate(); //启用验证
                var flag = $('#defaultForm').data('bootstrapValidator').isValid()//验证是否通过true/false
                if (flag) {
                    var url = "";
                    if ($.trim($("#btnBox").text()) == "提交") {
                        url = "../../BaseRefWeb.aspx?stype=ISpAddressFun&method=DoWebSave&type=sp";
                    }
                    else {
                        url = "../../BaseRefWeb.aspx?stype=ISpAddressFun&method=DoWebEdit&type=sp";
                    }
                    $("#defaultForm").ajaxSubmit({
                        type: "post",
                        url: url,
                        dataType: "json",
                        success: function (result) {
                            if (result.success == false) {
                                $('.phoneError').text(result.msg);
                                var top = ($(window).height() - $('.phoneError').height()) / 2;
                                var left = ($(window).width() - $('.phoneError').width()) / 2;
                                var scrollTop = $(document).scrollTop();
                                var scrollLeft = $(document).scrollLeft();
                                $('.phoneError').css({ position: 'absolute', 'top': top + scrollTop, left: left + scrollLeft }).show();
                                setTimeout(function () {
                                    $('.phoneError').hide();
                                }, 1000)
                            }
                            else {
                                window.location.href = "address.html";
                            }
                        }
                    });
                }
            });
            $('#defaultForm').bootstrapValidator({
                fields: {
                    name: {
                        validators: {
                            notEmpty: {
                                message: '姓名不能为空'
                            }
                        }
                    },
                    phone: {
                        validators: {
                            notEmpty: {
                                message: '手机号码不能为空'
                            },
                            stringLength: {
                                min: 11,
                                max: 11,
                                message: '请输入11位手机号码'
                            }
                        }
                    },
                    region: {
                        validators: {
                            notEmpty: {
                                message: '地区不能为空'
                            }
                        }
                    },
                    detailedAddress: {
                        validators: {
                            notEmpty: {
                                message: '详细地址不能为空'
                            }
                        }
                    },
                    postalCode: {
                        validators: {
                            notEmpty: {
                                message: '邮政编码不能为空'
                            }
                        }
                    }
                }
            });
        })
    </script>
</head>
<body>
    <div class="phoneError">
    </div>
    <div class="backBox" onclick="javascript:location.href = 'address.html';">
        <span class="glyphicon glyphicon-chevron-left"></span>
    </div>
    <div class="topTitle ">
        收货地址</div>
    <form id="defaultForm" onsubmit="return false">
    <div class="bigBox regBigBox">
        <div class="passBox form-group">
            <span class="">姓名：</span><input type="text" name="name" placeholder="请输入您的真实姓名" />
        </div>
        <div class="passBox form-group">
            <span class="">电话：</span><input type="text" name="phone" placeholder="请输入您的手机号" />
        </div>
        <div class="passBox form-group">
            <span class="">地区：</span><input type="text" name="region" placeholder="请输入省市地区" />
        </div>
        <div class="passBox form-group">
            <span class="">详细地址：</span><input type="text" name="detailedAddress" placeholder="请输入详细地址" />
        </div>
        <div class="passBox form-group">
            <span class="">邮政编码：</span><input type="text" name="postalCode" placeholder="请输入邮政编码" />
        </div>
        <div class="form-group form-group">
            <button type="submit" class="btn btnBox" id="btnBox">
                提交</button>
        </div>
    </div>
    </form>
</body>
</html>
